-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Contextualize credentials used by GitSCMFileSystem when possible
#1802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Contextualize credentials used by GitSCMFileSystem when possible
#1802
Conversation
| if (_build != null && credential != null && credential.forRun(_build) instanceof StandardCredentials standardCredential) { | ||
| credential = standardCredential; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: No sure if GitSCMTelescope should contextualize the credentials similarly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I looked into that, but IDK. There is also this credentials lookup in AbstractGitSCMSource which won't work, and I don't think it can be made to work:
git-plugin/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
Lines 1333 to 1338 in de7f436
| return CredentialsMatchers | |
| .firstOrNull( | |
| CredentialsProvider.lookupCredentialsInItem(StandardUsernameCredentials.class, context, | |
| ACL.SYSTEM2, URIRequirementBuilder.fromUri(getRemote()).build()), | |
| CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsId), | |
| GitClient.CREDENTIALS_MATCHER)); |
Going by https://github.com/search?type=code&q=+owner%3Ajenkinsci+gitscmtelescope, I think the answer here would just be that
GitSCMSource doesn't support inference-based options for GitHubAppCredentials, you must use GitHubSCMSource. IDK if there would ever be a reason that you would have to use GitSCMSource over GitHubSCMSource, but I don't think so.
For GitSCM and its use of GitSCMFileSystem, the situation is different, since there is no GitHubSCM.
| } | ||
|
|
||
| @Test | ||
| public void filesystem_supports_credential_contextualization() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I confirm that the test fails without the credentials contextualization.
After jenkinsci/github-branch-source-plugin#822, credential lookups for
GitHubAppCredentialsconfigured to use an inference-based repository access strategy fail when usingGitSCMFileSystem. NormallyGitHubSCMFileSystemis used instead ofGitSCMFileSystem, and that works fine, butGitSCMFileSystemgets used in cases where you have to configure aGitSCMdirectly, since there is no GitHub-specific SCM implementation.For example, you can run into this problem if you use "Pipeline script from SCM" to configure a Pipeline, enable lightweight checkout, and use
GitHubAppCredentialsfor theGitSCMcredentials.For more context, credential lookups for
GitHubAppCredentialswere expected to fall into one of two cases:Connector.lookupScanCredentials. This ensures proper owner inference and bypasses repository inference because the credential usage context is trusted. Plugins that need to do this kind of lookup may require changes like Use Connector.lookupScanCredentials to contextualize GitHubAppCredentials github-checks-plugin#398 (but others were already usingConnector.lookupScanCredentials).withCredentialsstep. Plugins that need to do this kind of lookup need to useCredentialsProvider.findCredentialByIdand pass an appropriateRuncontext for proper owner and repository inference, like is already done in this plugin inGitSCM.lookupScanCredentials.GitSCMFileSystemis a bit of an awkward spot. Conceptually, it falls under case 1 and should useConnector.lookupScanCredentialsto contextualizeGitHubAppCredentialsfor a trusted context, but we can't add agithub-branch-sourcedependency here or else we'll have circular dependencies. This leaves us with two options:credentialsthat is comparable toCredentials.forRunthat allows contextualization of generic credential lookups, and avoids the need to useConnector.lookupScanCredentialsdirectly when working withGitHubAppCredentialsGitHubSCMFileSystemwithGitSCM, or a GitHub-specific SCM implementation or similar that bypassesGitSCMFileSystemin this caseGitSCMFileSystem, although repository inference strategies would still not be supportedCC @jeromepochat
Testing done
See new automated test.
Submitter checklist